package com.nuoniu.sibanyun.controller.production;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nuoniu.sibanyun.common.BaseController;
import com.nuoniu.sibanyun.common.exception.NuoNiuException;
import com.nuoniu.sibanyun.common.lang.StringUtils;
import com.nuoniu.sibanyun.common.result.HttpResult;
import com.nuoniu.sibanyun.entity.erp.ErpWorkProcedure;
import com.nuoniu.sibanyun.service.erp.IErpAccountService;
import com.nuoniu.sibanyun.service.erp.IErpTeamService;
import com.nuoniu.sibanyun.service.erp.IErpWorkProcedureService;
import com.nuoniu.sibanyun.service.production.IErpStationService;
import com.nuoniu.sibanyun.userThread.UserInfo;
import com.nuoniu.sibanyun.userThread.UserThreadLocal;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * <p>
 * 工序管理 前端控制器
 * </p>
 *
 * @author 小啊刚
 * @since 2020-12-30
 */
@RestController
@RequestMapping("/erp/workProcedure")
@Api(value = "工序管理 ", tags = "工序管理")
public class ErpWorkProcedureController extends BaseController {

    @Autowired
    private IErpWorkProcedureService workProcedureService;

    @ApiOperation("保存工序")
    @PostMapping("save")
    public HttpResult save(@RequestBody ErpWorkProcedure workProcedure) {
        if(StringUtils.isBlank(workProcedure.getCode())) {
            throw new NuoNiuException("编码不能为空");
        }

        if(StringUtils.isBlank(workProcedure.getName())) {
            throw new NuoNiuException("名称不能为空");
        }

        workProcedureService.saveWorkProcedure(workProcedure);
        return HttpResult.ok();
    }

    @ApiOperation("获取工序列表")
    @GetMapping("pageList")
    public HttpResult pageList(Page page, ErpWorkProcedure workProcedure) {
        return HttpResult.ok(workProcedureService.pageList(page, workProcedure));
    }

    @ApiOperation("删除工序")
    @DeleteMapping("delete")
    public HttpResult deleteById(Long id) {
        workProcedureService.deleteById(id);
        return HttpResult.ok();
    }
}
